package com.example.offer.no0006.impl;

import java.util.ArrayList;
import java.util.List;

import com.example.offer.no0006.ListNode;
import com.example.offer.no0006.Solution;

/**
 * @author yumuhui <yumuhui@kuaishou.com>
 * Created on 2021-05-13
 */
public class RecurSolutionImpl implements Solution {

    List<Integer> list = new ArrayList<>();

    @Override
    public int[] reversePrint(ListNode node) {

        recur(node);
        int size = list.size();
        int[] print = new int[size];
        for (int i = 0; i < size; i++) {
            print[i] = list.get(i);
        }
        return print;
    }

    private void recur(ListNode node) {
        if (node == null) {
            return;
        }
        recur(node.next);
        list.add(node.val);
    }
}
